package edu.gmu.projects.fireresponder.fusionengine;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import edu.gmu.projects.fireresponder.environment.Asset;
import edu.gmu.projects.fireresponder.environment.Location;
import edu.gmu.projects.fireresponder.xml.alerts.Alert;

public abstract class AnchorPoint extends Location {

	private List<Asset> nearByAssets;
		
	protected List<Event> events;
	protected double probability;
	
	public AnchorPoint() {
		probability = 0;
		events = Collections.synchronizedList(new LinkedList<Event>());
	}
	
	protected void setProbability(double probability) {
		this.probability = probability;
	}
	
	public double getPointProbability() {
		return probability;
	}

	protected void setNearByAssets(List<Asset> nearByAssets) {
		this.nearByAssets = nearByAssets;
	}

	public List<Asset> getNearByAssets() {
		return nearByAssets;
	}

	protected abstract void updatePointProbability();	
	public abstract boolean addAlert(Alert alert);

	protected void addEvent(Alert alert) {
		events.add(new Event(alert.getTime().getTimeInMillis()));		
	}

	protected void addEvent(Alert alert, double score) {
		events.add(new Event(alert.getTime().getTimeInMillis(), score));		
	}

	protected void addEvent(Alert alert, boolean overridesCap) {
		events.add(new Event(alert.getTime().getTimeInMillis(), overridesCap));		
	}

	protected void addEvent(Alert alert, double score, boolean overridesCap) {
		events.add(new Event(alert.getTime().getTimeInMillis(), score, overridesCap));		
	}
	
	protected class Event {		
		protected long timeStamp;
		protected double score;
		protected boolean overridesCap;
		
		public Event(long timeStamp) {
			this.timeStamp = timeStamp;
			score = 1;
		}

		public Event(long timeStamp, double score) {
			this.timeStamp = timeStamp;
			this.score = score;
			this.overridesCap = false;
		}

		public Event(long timeStamp, boolean overridesCap) {
			this.timeStamp = timeStamp;
			score = 1;
			this.overridesCap = overridesCap;
		}

		public Event(long timeStamp, double score, boolean overridesCap) {
			this.timeStamp = timeStamp;
			this.score = score;
			this.overridesCap = overridesCap;
		}
		
	}
}
